//
// Copyright (C) 2011 - 2013  Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1
//#include "stdafx.h"
#include "MarketModelParametricExercise.h"
using namespace Cephei::QL::Models::Marketmodels::Callability;
#include <gen/QL/Models/Marketmodels/EvolutionDescription.h>
#include <gen/QL/Models/Marketmodels/CurveState.h>
#include <gen/QL/Models/Marketmodels/Callability/MarketModelNodeDataProvider.h>
#include <gen/QL/Methods/Montecarlo/ParametricExercise.h>
using namespace Cephei::QL::Models::Marketmodels;
using namespace Cephei::QL::Methods::Montecarlo;
#undef HANDLE
#define ABSTRACT
#undef STRUCT
Cephei::QL::Models::Marketmodels::Callability::CMarketModelParametricExercise::CMarketModelParametricExercise (boost::shared_ptr<QuantLib::MarketModelParametricExercise>& childNative, Object^ owner) : CMarketModelNodeDataProvider(CMarketModelParametricExercise::typeid)
{
#ifdef HANDLE
	_phMarketModelParametricExercise = NULL;
#endif
	_ppMarketModelParametricExercise = &childNative;
    _ppMarketModelNodeDataProvider = new boost::shared_ptr<QuantLib::MarketModelNodeDataProvider> (boost::dynamic_pointer_cast<QuantLib::MarketModelNodeDataProvider> (*_ppMarketModelParametricExercise));
}
Cephei::QL::Models::Marketmodels::Callability::CMarketModelParametricExercise::CMarketModelParametricExercise (QuantLib::MarketModelParametricExercise& childNative, Object^ owner) : CMarketModelNodeDataProvider(CMarketModelParametricExercise::typeid)
{
#ifdef HANDLE
	_phMarketModelParametricExercise = NULL;
#endif
	_ppMarketModelParametricExercise = new boost::shared_ptr<QuantLib::MarketModelParametricExercise> (&childNative);
    _ppMarketModelNodeDataProvider = new boost::shared_ptr<QuantLib::MarketModelNodeDataProvider> (boost::dynamic_pointer_cast<QuantLib::MarketModelNodeDataProvider> (*_ppMarketModelParametricExercise));
    _MarketModelParametricExerciseOwner = owner;
    _MarketModelNodeDataProviderOwner = owner;
}

Cephei::QL::Models::Marketmodels::Callability::CMarketModelParametricExercise::CMarketModelParametricExercise (CMarketModelParametricExercise^ copy) : CMarketModelNodeDataProvider(CMarketModelParametricExercise::typeid)
{
#ifdef HANDLE
	_phMarketModelParametricExercise = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppMarketModelParametricExercise = new boost::shared_ptr<QuantLib::MarketModelParametricExercise> (copy->GetShared());
        _ppMarketModelNodeDataProvider = new boost::shared_ptr<QuantLib::MarketModelNodeDataProvider> (boost::dynamic_pointer_cast<QuantLib::MarketModelNodeDataProvider> (*_ppMarketModelParametricExercise));
    }
}
Cephei::QL::Models::Marketmodels::Callability::CMarketModelParametricExercise::CMarketModelParametricExercise (PLATFORM::Type^ t) : CMarketModelNodeDataProvider(CMarketModelParametricExercise::typeid)
{
#ifdef HANDLE
	_phMarketModelParametricExercise = NULL;
#endif
	if (!t->IsSubclassOf(CMarketModelParametricExercise::typeid))
		throw REFNEW Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Models::Marketmodels::Callability::CMarketModelParametricExercise::CMarketModelParametricExercise (QuantLib::Handle<QuantLib::MarketModelParametricExercise>& childNative, Object^ owner)  : CMarketModelNodeDataProvider(CMarketModelParametricExercise::typeid)
{
	_phMarketModelParametricExercise = &childNative;
	_ppMarketModelParametricExercise = &static_cast<boost::shared_ptr<QuantLib::MarketModelParametricExercise>>(childNative.currentLink());
    _ppMarketModelNodeDataProvider = new boost::shared_ptr<QuantLib::MarketModelNodeDataProvider> (boost::dynamic_pointer_cast<QuantLib::MarketModelNodeDataProvider> (*_ppMarketModelParametricExercise));
    _MarketModelParametricExerciseOwner = owner;
}
Cephei::QL::Models::Marketmodels::Callability::CMarketModelParametricExercise::CMarketModelParametricExercise (QuantLib::Handle<QuantLib::MarketModelParametricExercise> childNative)  : CMarketModelNodeDataProvider(CMarketModelParametricExercise::typeid)
{
	_phMarketModelParametricExercise = &childNative;
	_ppMarketModelParametricExercise = &static_cast<boost::shared_ptr<QuantLib::MarketModelParametricExercise>>(childNative.currentLink());
    _ppMarketModelNodeDataProvider = new boost::shared_ptr<QuantLib::MarketModelNodeDataProvider> (boost::dynamic_pointer_cast<QuantLib::MarketModelNodeDataProvider> (*_ppMarketModelParametricExercise));
}
#endif
#ifdef STRUCT
Cephei::QL::Models::Marketmodels::Callability::CMarketModelParametricExercise::CMarketModelParametricExercise (QuantLib::MarketModelParametricExercise childNative)  : CMarketModelNodeDataProvider(CMarketModelParametricExercise::typeid)
{
#ifdef HANDLE
	_phMarketModelParametricExercise = NULL;
#endif
	_ppMarketModelParametricExercise = new boost::shared_ptr<QuantLib::MarketModelParametricExercise> (new QuantLib::MarketModelParametricExercise (childNative));
    _ppMarketModelNodeDataProvider = new boost::shared_ptr<QuantLib::MarketModelNodeDataProvider> (boost::dynamic_pointer_cast<QuantLib::MarketModelNodeDataProvider> (*_ppMarketModelParametricExercise));
}
#endif

Cephei::QL::Models::Marketmodels::Callability::CMarketModelParametricExercise::~CMarketModelParametricExercise ()
{
    if (_ppMarketModelParametricExercise != NULL)
    {
	    delete _ppMarketModelParametricExercise;
        _ppMarketModelParametricExercise = NULL;
    }
}
Cephei::QL::Models::Marketmodels::Callability::CMarketModelParametricExercise::!CMarketModelParametricExercise ()
{
    if (_ppMarketModelParametricExercise != NULL)
    {
	    delete _ppMarketModelParametricExercise;
    }
}
QuantLib::MarketModelParametricExercise& Cephei::QL::Models::Marketmodels::Callability::CMarketModelParametricExercise::GetReference ()
{
    if (_ppMarketModelParametricExercise == NULL) throw REFNEW NativeNullException ();
	return **_ppMarketModelParametricExercise;
}
boost::shared_ptr<QuantLib::MarketModelParametricExercise>& Cephei::QL::Models::Marketmodels::Callability::CMarketModelParametricExercise::GetShared ()
{
    if (_ppMarketModelParametricExercise == NULL) throw REFNEW NativeNullException ();
	return *_ppMarketModelParametricExercise;
}
QuantLib::MarketModelParametricExercise* Cephei::QL::Models::Marketmodels::Callability::CMarketModelParametricExercise::GetPointer ()
{
    if (_ppMarketModelParametricExercise == NULL) throw REFNEW NativeNullException ();
	return &**_ppMarketModelParametricExercise;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::MarketModelParametricExercise>& Cephei::QL::Models::Marketmodels::Callability::CMarketModelParametricExercise::GetHandle ()
{
	if (_phMarketModelParametricExercise == NULL)
	{
		_phMarketModelParametricExercise = new Handle<QuantLib::MarketModelParametricExercise> (*_ppMarketModelParametricExercise);
	}
	return *_phMarketModelParametricExercise;
}
#endif
bool Cephei::QL::Models::Marketmodels::Callability::CMarketModelParametricExercise::HasNative () 
{
	return (_ppMarketModelParametricExercise != NULL);
}

Cephei::Core::IVector<UInt64>^ Cephei::QL::Models::Marketmodels::Callability::CMarketModelParametricExercise::NumberOfData::get ()
{
    try
    {
    	std::vector<QuantLib::Size> _rv = (std::vector<QuantLib::Size>)(*_ppMarketModelParametricExercise)->numberOfData ( );   
        Cephei::Core::IVector<UInt64>^ _nrv = REFNEW CoVector<UInt64> (REFNEW CUInt64Vector (_rv));
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

